<?php
/**
 * Conversations - A lightweight BB for Xaraya
 *
 * @package modules
 * @copyright (C) 2003-2006 The Digital Development Foundation.
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html}
 * @link http://www.xaraya.com
 *
 * @subpackage conversations
 * @link http://xaraya.com/index.php/release/760.html
 * @author John Cox
*/
/**
 * Delete a tag
 * 
 * @package Xaraya eXtensible Management System
 * @copyright (C) 2005 by the Xaraya Development Team.
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html}
 * @link http://www.xaraya.org
*/
/**
 * delete a tag
 * @param $args['id'] integer
 * @returns bool
 * @return true on success, false on failure
 */
function conversations_userapi_deletetag($args)
{
  
    extract($args);
    
    if (isset($tagid)) {
      $id = $tagid;
    }
    
    if (!isset($id)) {
        $msg = xarML('Invalid Parameter Count');
        xarErrorSet(XAR_SYSTEM_EXCEPTION, 'BAD_PARAM', new SystemException($msg));
        return;
    }
    // This gets a little tricky here with the look up table
    // We don't want to delete the posts here.  Do it in the user function.
    // Problem comes in with the merges and the splits...

    xarModAPIFunc('conversations', 'user', 'deletelook', array('tagid' => $id));
    // We need to delete all subscriptions that are associated with this tag (if any)
    
    xarModAPIFunc('conversations', 'user', 'deletesubs', array('tagid' => $id));
    // TODO we probably also should penalize the user karma...
    
    // Get datbase setup
    $dbconn =& xarDBGetConn();
    $xartable =& xarDBGetTables();
    $table = $xartable['ctags'];

    // Delete the item
    $query = "DELETE FROM $table WHERE xar_id = ?";
    $result =& $dbconn->Execute($query, array($id));
    if (!$result) return;

    // Let any hooks know that we have deleted a forum
    $args['module'] = 'conversations';
    $args['itemtype'] = 1;
    $args['itemid'] = $id;
    xarModCallHooks('item', 'delete', $id, $args);
    return true;
}
?>